import React from 'react';
import propTypes from 'prop-types';

const Slot = ({ name, children }, { requestAddOnRenderer }) => {
  const addOnRenderer = requestAddOnRenderer(name);
  return (addOnRenderer && addOnRenderer()) || children || null;
}

Slot.displayName = 'Slot';

Slot.contextTypes = { requestAddOnRenderer: propTypes.func };
Slot.propTypes = { name: propTypes.string };
Slot.defaultProps = { name: '$$default' };

export default Slot;